package com.cheer.dao;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cheer.entity.ConfigSwitch;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 文档模板表
 * 
 * @author chufangzheng
 * @email 1280251739@qq.com
 * @date 2021-10-20 16:11:30
 */
@Mapper
public interface ConfigSwitchDao extends BaseMapper<ConfigSwitch> {

    /**
     * 根据别名信息获取配置
     * @param alias
     * @return
     */
    default ConfigSwitch getByAlias(String alias) {

        QueryWrapper<ConfigSwitch> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ConfigSwitch::getAlias, alias).eq(ConfigSwitch::getIsDeleted, 0);
        List<ConfigSwitch> configSwitches = selectList(queryWrapper);
        if(CollectionUtil.isNotEmpty(configSwitches)){
            return configSwitches.get(0);
        }
        return null;
    }
}
